define(['jquery'], function($) {
  var that = {};
  var promise;

  var count = 0;

  var retry = function(config) {
    count++;
    that.baseServ(config);
  };

  var baseServ  = function(data) {
    data = data || {};
    var defaultData = {
      //url: baseUrl + data.url,
      url: data.url,
      type: data.method || 'get',
      dataType: data.dataType || 'jsonp',
      data: data.param || {},
    };

    if (defaultData.dataType === 'jsonp') {
      defaultData.jsonp = 'callback';
      defaultData.jsonpCallback = 'callback';
    };

    var promise = $.ajax(defaultData);
    promise.fail(function(err) {
      console.log('fail');

      if (count < 3) {
        that.retry(this);
      };
    });
    return promise;
  };

  that.baseServ = baseServ;
  that.retry = retry;
  return that;
});
